/**************************************************************************
 * @doc CPAC
 * @module CPAC CPACSRC.H |  
 * Source code for the CPAC handling functions.
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team (I_SP2000).
 * <nl>Notes       :
 * @head3 CPAC Functions |
 * @index | CPAC
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 * 
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form 
 * or by any means whether electronic, mechanical, magnetic, optical, 
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/CPACSrc/cpacsrc.h $

********************************************************************************/

#ifndef _CPACSRC_H_
#define _CPACSRC_H_

#include <iso8583.h>
#include <amexhost.h>
#include <transact.h>
#include "..\cpacsrc\cpac.h"
#include <protocol.h>
#include <packet.h>

#define CPAC_RESPONSE_FILE "resp"  // CPAC_UNBKL added for error response disp.
#define TICKET_ID_SIZE	13
#define PRIVATE_LABEL_SIZE	10
////////////////////////////////////////////////////////////////////
//
// E X T E R N   D E C L A R A T I O N S
//

/* Function Prototypes */
#ifdef __thumb
char *msg_get( unsigned int, char * );
int msg_select_file( char * );
#endif

#ifdef _TARG_68000
extern char *msg_get( unsigned int, char * );
extern int msg_select_file( char * );
#endif

////////////////////////////////////////////////////////////////////
//
// F U N C T I O N   P R O T O T Y P E S
//
int inModifyCPACBatchRec(TRANSACTION_OBJECT* pobTran);
int inCPACPIPAnalyse(PACKET_OBJECT* pobPacket);
int inUploadCPACAdvices(VS_BOOL fSettle,TRANSACTION_OBJECT* pobTran);
int inCPACPIPDeinitialize(PACKET_OBJECT* pobPacket);

int inCPACCreateVariantStruct60(void);
int inCPACCreateVariantStruct63(void);


void vdCPACDeleteTabAdvice(HOST_8583_DATA* psrHostType);
void vdCPACResetTrans(TRANSACTION_OBJECT* pobTran);
void vdCPACDispRespMsg(TRANSACTION_OBJECT* pobTran);
void vdCPACSyncHostDateTime(char* hostdate,char* hosttime);
int inCPACDoReversal(TRANSACTION_OBJECT* pobTran,int inISOSendSize);
int inUpdateCPACReversal(COMM_8583_DATA* srCommStruct); // CPAC_UNBKL added

void vdAddCPACFunctions(void);
int inInitializeCPACValidationStruct(TRANSACTION_OBJECT* pobTran,VALIDATION_STRUCT* psrValidationParameters);
void vdInitializeCPAC(PACKET_OBJECT* pobPacket);
int inCPACInit(PACKET_OBJECT* pobPacket);
void vdCPACError(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket,int inError);
int inSendReceiveCPAC(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket);
short shVerifyCPACTransType(TRANSACTION_OBJECT* pobTran);
int inSetCPACOffOnLine(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACParams(CPAC_REC* psrCPAC);
void vdLoadHostParams(CPAC_REC* psrCPAC,char* szHostName);
void vdLoadCPACField04(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField14(TRANSACTION_OBJECT* pobTran);  // MALAYSIA_CPAC 
//leo_nosourcesafe
void vdLoadCPACField22(TRANSACTION_OBJECT* pobTran) ;
void vdLoadCPACField22(TRANSACTION_OBJECT* pobTran); 
void vdLoadCPACField24(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField37(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField39(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField42(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField41(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField48(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField52(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField54(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField60(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField61(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField62(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField63(TRANSACTION_OBJECT* pobTran);
void vdLoadCPACField64(TRANSACTION_OBJECT* pobTran);
int inSetCPACTransFields(TRANSACTION_OBJECT* pobTran,int host,unsigned int inTransCode,char* szProcCode);
void vdGetCPACTPDU(char* pchTPDU);
int inGetCPACReceiptFields(TRANSACTION_OBJECT* pobTran);
int inSettleCPAC(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket);
extern int inCBTUpdateAccumFlow(TRANSACTION_OBJECT* pobTran);
extern ISOLOAD srCPACLoadDataFuncs[];
int inCPACGetCheckMID(TRANSACTION_OBJECT* pobTran);
extern int inLoadCPACRecForPowerFail(TRANSACTION_OBJECT* pobTran) ;
extern int inCITIUserChoice(TRANSACTION_OBJECT* pobTran);
extern int inRemoveLastRecieptFile(TRANSACTION_OBJECT* pobTran);
extern int inCPACLoadMissingTable(TRANSACTION_OBJECT* pobTran);
extern void DisplayStatus(char *msg);
extern int inImamVivoPtSaleTopup (TRANSACTION_OBJECT *pobTran);
extern  void vdScrollDisplay(void);
int inCheckMultiBatchEmpty(TRANSACTION_OBJECT* pobTran);
extern int inSingleBatchClearOperation(TRANSACTION_OBJECT* pobTran);
int inUpdateOfflineAccum(TRANSACTION_OBJECT* pobTran,ACCUM_VALUES* psrAccum);
extern int inImamReferralSendReceive(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket) ;
extern VS_BOOL fGetReversal(TRANSACTION_OBJECT* pobTran);
extern VS_BOOL fGetOffline(TRANSACTION_OBJECT* pobTran);
extern VS_BOOL fGetCheckFloorLimit(TRANSACTION_OBJECT* pobTran);
//leo_noSourceSafe
extern void vdFormatCITIDate(char* pchDate);
#ifdef CITI_PHIL
extern void vdMaskCitiMTID(void);
int inPhilUserChoice(TRANSACTION_OBJECT* pobTran);
extern long (*lnValidateVoidsAndAdjusts)(TRANSACTION_OBJECT*);

#endif /* CITI_PHIL */
int inCPACSettleAHost(TRANSACTION_OBJECT* pobTran);
int pCPACSettleAllHosts(TRANSACTION_OBJECT* pobTran);
int inCPACSettleOperation(TRANSACTION_OBJECT* pobTran);
int inCPACAutoSettleOperation(TRANSACTION_OBJECT* pobTran); 
int inCPACKeyFunc2(TRANSACTION_OBJECT* pobTran); 
int inCPACSetSettleCode(TRANSACTION_OBJECT* pobTran) ;
int inDailyPayment(TRANSACTION_OBJECT* pobTran);
int inCPACDailyPayment(TRANSACTION_OBJECT* pobTran);

extern VS_BOOL fChkHostBatches(TRANSACTION_OBJECT* pobTran,int inCount); 
VS_BOOL fBatchEmpty(TRANSACTION_OBJECT* pobTran,VS_BOOL fClose); 

extern long lnProceedWithSettlement(TRANSACTION_OBJECT* pobTran);
extern void vdDisplayNoSettleMsg(long lnMsgID);
extern char* szGetMerchantText(void);
extern int inConfirmSettle(TRANSACTION_OBJECT* pobTran);
extern int inCallZontalk(char chZonType);
extern int inFakeSettle(TRANSACTION_OBJECT* pobTran);
extern int inRunSettleProtocolFunction(TRANSACTION_OBJECT* pobTran);
extern int inPrintSettlementReport(TRANSACTION_OBJECT* pobTran,VS_BOOL fBatchReport,VS_BOOL fSettleSucceeded,VS_BOOL fCommErr);
extern int inResetAccum(void);
extern int inResetSTT(TRANSACTION_OBJECT* pobtran);
int inCITIGetBatchNumber(TRANSACTION_OBJECT* pobTran);
int inCITIGetSettDate(TRANSACTION_OBJECT* pobTran);
int inGetAirlineCode(TRANSACTION_OBJECT* pobTran);
extern int inValidateString(char* szString);
extern int inGetCVV2Type(void);
extern int inEnterWithMessage(long lnMessageNumber,VS_BOOL fScrollDisplay,char* szResponseString,int inDataType,int inMaxChars,int  (*inValidator) (char* szResponseString));
// extern int inSetToMainMenu (Void);
int inCPACSetMustSettleFlag(TRANSACTION_OBJECT* pobTran);
int inCPACTransNameDisplay(TRANSACTION_OBJECT* pobTran);
int inCPACDisplayResponse(TRANSACTION_OBJECT* pobTran);
int inCPACTipPercentValid(char* pchValue);
int inCPACDispTransName(TRANSACTION_OBJECT* pobTran);

extern void vdSetTRTf1(TRANSACTION_OBJECT* pobTran,VS_BOOL param);  //Set "Print Bank Copy" Flag
extern VS_BOOL fGetTRTf1(TRANSACTION_OBJECT* pobTran);                   //Get "Print Bank Copy" Flag
extern void vdSetTRTf2(TRANSACTION_OBJECT* pobTran,VS_BOOL param);  //Set "Print Customer Copy" Flag
extern VS_BOOL fGetTRTf2(TRANSACTION_OBJECT* pobTran);                   //Get "Print Customer Copy" Flag
extern void vdSetTRTf3(TRANSACTION_OBJECT* pobTran,VS_BOOL param);  //Set "Print Merchant Copy" Flag
extern VS_BOOL fGetTRTf3(TRANSACTION_OBJECT* pobTran);                   //Get "Print Merchant Copy" Flag
#endif 
int inCPACDemo(TRANSACTION_OBJECT* pobTran);
#ifdef EMV_MODULE
extern int inEMVDemo(TRANSACTION_OBJECT* pobTran);
#endif /* EMV_MODULE */
#ifdef VXEMVAPP
//extern int inVXEMVAPPDemo(TRANSACTION_OBJECT *pobTran);
extern int inDemoFunction(TRANSACTION_OBJECT *pobTran);
#endif /* EMV_MODULE */
extern int inEditCSTOperation(TRANSACTION_OBJECT* pobTran);
extern int inEditLCTOperation(TRANSACTION_OBJECT* pobTran);

#ifdef DOWNLOAD_MULTIPLE_LOGO
extern int inMultipleDownloadLogo(int inWhichOne);
#else
extern int inMultipleDownloadLogo(int inWhichOne);
#endif /*DOWNLOAD_MULTIPLE_LOGO*/

extern int inCPACClearAdvice(TRANSACTION_OBJECT* pobTran);

int inCPACCheckValidInvNum(TRANSACTION_OBJECT* pobTran);
int inCPACStoreSelectedHostIndex(TRANSACTION_OBJECT* pobTran);
int inCPACValidateVoid(TRANSACTION_OBJECT* pobTran);
int inCPACValidateAdjust(TRANSACTION_OBJECT* pobTran);
int inCPACClearReversal(TRANSACTION_OBJECT* pobTran);
int inCPACRestartAfter24Days(TRANSACTION_OBJECT *pobTran);
int inCPACPrintPacketLog(TRANSACTION_OBJECT *pobTran);
extern int inPrintISO8583PacketLog(void);
void vdCITINormalBeep(int inDelay);
#ifdef _TARG_68000
void vdImamGetMessageFromThisFile(const  char* szFileNameSuffix, char *szMessageCode, char* szMessageBuffer) ;
#endif	
extern void vdTrimSpace(char *buff);
extern void vdFormatText(char *buff, int kolom, int Justify);
#ifdef TCPIP_DEFINED

void vdInitializeTCPIPComm(COMM_OBJECT* obCommunication);
int Send_Modem_AT_Command(char* sCmd,int iLenCmd,char* sRcv);
int Send_LAN_AT_Command(char* sCmd,int iLenCmd,char* sRcv); 
int inInitTCPIPCommunication(COMM_OBJECT* obCommunication);
int inBeginTCPIPCommunication(COMM_OBJECT* obCommunication,int inCPTIndex,VS_BOOL fUsePrimaryLine);
int inCheckTCPIPCommunication(COMM_OBJECT* obCommunication);
int inSendTCPIPCommunication(COMM_OBJECT* obCommunication,char* pchSendBuff,int inSendSize,VS_BOOL fConfirmSend,int inTimeout,long lnMessage);

int inReceiveTCPIPCommunication(COMM_OBJECT* obCommunication,char* pchReceiveBuff,int inReceiveSize,int inReceiveTimeout,long lnMessage);

int inEndTCPIPCommunication(COMM_OBJECT* obCommunication);
int inFlushTCPIPCommunication(void);
int inDeInitTCPIPCommunication(COMM_OBJECT* obCommunication);

extern int inCPACDoReversal(TRANSACTION_OBJECT* pobTran,int inISOSendSize);
extern void DisplayStatus(char *msg);
extern int inGetUCLCommLink(void);
extern int inImamVivoPtSaleTopup (TRANSACTION_OBJECT *pobTran);
extern void vdScrollDisplay(void);
extern int inImamReferralSendReceive(PROTOCOL_OBJECT* pobProtocol,PACKET_OBJECT* pobPacket) ;
extern void DisplayStatus(char *msg);

extern int inImamVivoPtSaleTopup (TRANSACTION_OBJECT *pobTran); 
 int get_env_x(char *param, int n, char *buff);


#endif /* TCPIP_DEFINED */


